package com.laoli.myspringboottest.event.listener;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.laoli.myspringboottest.entity.TableA;
import com.laoli.myspringboottest.mapper.TableAMapper;
import com.laoli.myspringboottest.event.TestEvent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@AllArgsConstructor
public class TestListener {

    private final TableAMapper tableAMapper;

    @EventListener(TestEvent.class)
    @Async
    public void saveLog(TestEvent event) throws InterruptedException {
        Thread.sleep(3000);
        log.info("LogEventListener:" + event.getTestItem().getName());
    }


    @EventListener(TestEvent.class)
    @Async
    public void saveLog2(TestEvent event) throws Exception {

        List<TableA> list = tableAMapper.selectList(new QueryWrapper<TableA>());
        log.info("LogEventListener-2:" + list.toString());
    }
}
